//
//  ECOthersLoginViewController.m
//  Edu_iOS
//
//  Created by apple on 2017/9/11.
//  Copyright © 2017年 yanyan. All rights reserved.
//



#import "ECOthersLoginViewController.h"
#import "UINavigationBar+Awesome.h"

@interface ECOthersLoginViewController()<UIGestureRecognizerDelegate>{
    ///上部背景图片
    UIImageView *headImageViewBg;
    ///三方登录图片
    UIImageView *thirdLoginOfImage;
    ///三方登录解释lab(第一行)
    UILabel *thirdLoginOfLabTop;
    ///三方登录解释lab(第二行)
    UILabel *thirdLoginOfLabBottom;
}

@end

@implementation ECOthersLoginViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self.navigationController.navigationBar lt_reset];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
    
    self.title = @"第三方登录";
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"navigation_Return"] style:UIBarButtonItemStylePlain target:self action:@selector(action_dismiss)];
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:19],
                                                                      NSForegroundColorAttributeName:[UIColor colorWithRed:51.f/255.f green:51.f/255.f blue:51.f/255.f alpha:1.00f]}];
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return YES;
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
    return YES;
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.thirdLoginWay = 1;

    headImageViewBg = [[UIImageView alloc]init];
    [self.view addSubview:headImageViewBg];
    headImageViewBg.image = [UIImage imageNamed:@"ThirdLogin_headImageView_Bg"];
    [headImageViewBg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).mas_offset(64);
        make.left.right.mas_offset(0);
        make.height.equalTo(@(kScreenWidth *(300.f/720.f)*kPercentage));
    }];
    
    thirdLoginOfImage = [[UIImageView alloc]init];
    [headImageViewBg addSubview:thirdLoginOfImage];
    [thirdLoginOfImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(headImageViewBg.mas_centerX);
        make.top.mas_equalTo(headImageViewBg.mas_top).mas_offset(20);
        make.width.equalTo(@(585*KProportion1080_Width));
        make.height.equalTo(@(85*KProportion1080_Heigh));
    }];
    
    thirdLoginOfLabTop = [[UILabel alloc]init];
    [headImageViewBg addSubview:thirdLoginOfLabTop];
    thirdLoginOfLabTop.textAlignment = NSTextAlignmentCenter;
    thirdLoginOfLabTop.font = [UIFont systemFontOfSize:15];
    thirdLoginOfLabTop.textColor = [UIColor colorWithRed:51.f/255.f green:51.f/255.f blue:51.f/255.f alpha:1];
    [thirdLoginOfLabTop mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(thirdLoginOfImage.mas_centerX);
        make.top.mas_equalTo(thirdLoginOfImage.mas_bottom).mas_offset(20*kPercentage);
        make.width.equalTo(@(kScreenWidth));
        make.height.equalTo(@(20));
    }];
    
    thirdLoginOfLabBottom = [[UILabel alloc]init];
    [headImageViewBg addSubview:thirdLoginOfLabBottom];
    thirdLoginOfLabBottom.textAlignment =NSTextAlignmentCenter;
    thirdLoginOfLabBottom.font = [UIFont systemFontOfSize:15];
    thirdLoginOfLabBottom.textColor = [UIColor colorWithRed:51.f/255.f green:51.f/255.f blue:51.f/255.f alpha:1];
    [thirdLoginOfLabBottom mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(thirdLoginOfLabTop.mas_centerX);
        make.top.mas_equalTo(thirdLoginOfLabTop.mas_bottom).mas_offset(5*kPercentage);
        make.width.equalTo(@(kScreenWidth));
        make.height.equalTo(@(20));
    }];
    
    UILabel *noAccountLab = [[UILabel alloc]init];
    noAccountLab.text = @"还没有学缘网账号";
    noAccountLab.textAlignment = NSTextAlignmentCenter;
    noAccountLab.font = [UIFont systemFontOfSize:15];
    noAccountLab.textColor = [UIColor colorWithRed:128.f/255.f green:128.f/255.f blue:128.f/255.f alpha:1.00f];
    [self.view addSubview:noAccountLab];
    [noAccountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(headImageViewBg.mas_bottom).mas_offset(90.f*KProportion1080_Heigh);
        make.width.mas_equalTo(headImageViewBg.mas_width);
        make.height.equalTo(@(45.f*KProportion1080_Heigh));
    }];
    
    ECUButton *registeredBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:registeredBtn];
    [registeredBtn setTitle:@"注册绑定" forState:0];
    [registeredBtn setTitleColor:[UIColor colorWithRed:255.f/255.f green:103.f/255.f blue:0 alpha:1.00f] forState:0];
    [registeredBtn setBackgroundImage:[UIImage imageNamed:@"flatButton_borderNormal"] forState:0];
    [registeredBtn setAdjustsImageWhenHighlighted:NO];
    registeredBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [registeredBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(noAccountLab.mas_bottom).mas_offset(42.f*KProportion1080_Heigh);
        make.left.mas_equalTo(self.view.mas_left).mas_offset(106.f*KProportion1080_Width);
        make.right.mas_equalTo(self.view.mas_right).mas_offset(-(106.f*KProportion1080_Width));
        make.height.mas_equalTo(registeredBtn.mas_width).multipliedBy(96.f/580.f);
    }];
    UILabel *haveAccountLab = [[UILabel alloc]init];
    haveAccountLab.text = @"已有学缘网账号";
    haveAccountLab.textAlignment = NSTextAlignmentCenter;
    haveAccountLab.font = [UIFont systemFontOfSize:15];
    haveAccountLab.textColor = [UIColor colorWithRed:0.49f green:0.49f blue:0.49f alpha:1.00f];
    [self.view addSubview:haveAccountLab];
    [haveAccountLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.top.mas_equalTo(registeredBtn.mas_bottom).mas_offset(144.f*KProportion1080_Heigh);
        make.width.mas_equalTo(noAccountLab.mas_width);
        make.height.equalTo(@(45*KProportion1080_Heigh));
    }];
    
    ECUButton *loginBtn = [ECUButton buttonWithType:UIButtonTypeCustom];
    [self.view addSubview:loginBtn];
    [loginBtn setTitle:@"登录绑定" forState:0];
    [loginBtn setTitleColor:[UIColor whiteColor] forState:0];
    [loginBtn setBackgroundImage:[UIImage imageNamed:@"registered_btn_bg"] forState:0];
    [loginBtn setAdjustsImageWhenHighlighted:NO];
    loginBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(haveAccountLab.mas_bottom).mas_offset(42*KProportion1080_Heigh);
        make.width.mas_equalTo(registeredBtn.mas_width);
        make.height.mas_equalTo(registeredBtn.mas_height);
        make.centerX.mas_equalTo(registeredBtn.mas_centerX);
    }];
    
    
    [self setvalueOfThirdWayWith:self.thirdLoginWay];
    
    
}

-(void)setvalueOfThirdWayWith:(ThirdLoginWay)thirdLoginWay{
    if (thirdLoginWay == 0) {//QQ登录
        thirdLoginOfImage.image = [UIImage imageNamed:@"ThirdLogin_thirdLoginOfImage_QQ"];
        thirdLoginOfLabTop.text = @"QQ帐号授权成功!";
        thirdLoginOfLabBottom.text = @"绑定学缘网账号，即可使用QQ一键登录";
    }else{
        thirdLoginOfImage.image = [UIImage imageNamed:@"ThirdLogin_thirdLoginOfImage_Wechat"];
        thirdLoginOfLabTop.text = @"微信帐号授权成功!";
        thirdLoginOfLabBottom.text = @"绑定学缘网账号，即可使用微信一键登录";
    }
}


-(void)action_dismiss{
    [self.navigationController popViewControllerAnimated:YES];
}

-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
